# ##### BEGIN GPL LICENSE BLOCK #####
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

# <pep8 compliant>

__author__ = "Mike Gehl"
__bpydoc__ = """\
This script Exports X-Plane v8 OBJ format.

"""

import bpy
from b2xp_utils import B2XP_DataRef


class B2XP_Exporter(bpy.types.Operator):
    '''Export an X-Plane OBJ file'''
    bl_idname = "export_obj"
    bl_label = "Export OBJ"

    def execute(self, context):
        """

        """
        scene = bpy.context.scene
        base_file_name = bpy.context.main.filename
        script_paths = bpy.utils.script_paths()

        try:
            data_refs = B2XP_DataRef(script_paths)
        except IOError as ee:
            self.report({'WARNING'}, ee.args[1])
            return {'FINISHED'}  


        #scene = Blender.Scene.GetCurrent()

        #baseFileName=Blender.Get('filename')
        #l = baseFileName.lower().rfind('.blend')
        #if l==-1: raise ExportError('Save this .blend file first')
        #baseFileName=baseFileName[:l]
        #(datarefs,foo)=getDatarefs()

        self.report({'WARNING'}, "DONE! Export Complete.")
        return {'FINISHED'}


class B2XP_Export8():

    def __init__(self, expobj, child, bone=None):
        pass


menu_func = lambda self, context: self.layout.operator(B2XP_Exporter.bl_idname, text="X-Plane OBJ (.obj)")


def register():
    bpy.types.register(B2XP_Exporter)
    bpy.types.INFO_MT_file_export.append(menu_func)


def unregister():
    bpy.types.unregister(B2XP_Exporter)
    bpy.types.INFO_MT_file_export.remove(menu_func)

if __name__ == "__main__":
    register()